<%@page import="com.multysite.entity.News"%>
<%@page import="com.multysite.model.NewsModel"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="com.multysite.entity.admin.Application"%>
<%@page import="java.util.TreeMap"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@page import="com.google.appengine.api.users.UserService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%	
	NewsModel model = (NewsModel) request
			.getAttribute("model");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List News</title>
<style>
.error {
	color: red;
}
</style>
<script type="text/javascript" src="/admin/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$(".btnDelete").click(function(){		
			var newsAlias = $(this).attr("href");
			if(confirm("Are you sure want to delete this news ?")){				
				$.get("/admin/news/process", {
					action : "delete",
					alias : newsAlias,
				}, function(data) {
					alert(data);	
				});
			}
			return false;
		});
	});
</script>
</head>
<body>
	<table style="padding: 2px; margin: 2px;">
		<tr>
			<td>Title</td>			
			<td>Action</td>
		</tr>
		<%
			if(model!=null&&model.getListResult().size()>0){
				for(News obj: model.getListResult()){									
		%>
		<tr>
			<td><%=obj.getTitle() %></td>			
			<td>
				<a href="/<%=obj.getAlias()%>.html" target="blank"">View</a>&nbsp;|&nbsp;
				<a class="btnEdit" href="/admin/news/edit?alias=<%=obj.getAlias()%>">Edit</a>&nbsp;|&nbsp;
				<a class="btnDelete" href="<%=obj.getAlias()%>">Delete</a>				
			</td>
		</tr>
		<%
				}
			}	
		%>		
	</table>
	<p>
		<%
			if(model.getPage()>1){
				%>
				<a href="/admin/news/list/?page=<%=(model.getPage()-1)%>">Previous</a>|
				<%
			}			
		%>
		<%
			if(model.getPage()<model.getTotalPage()){
				%>
				<a href="/admin/news/list/?page=<%=(model.getPage()+1)%>">Next</a>
				<%
			}
		%>			
	</p>	
	<a href="/admin/news/add">Add News</a>&nbsp;|&nbsp;<a href="/admin">Application Setting</a>
</body>
</html>